//
//  ZCUserView.m
//  百思不得姐
//
//  Created by Ning Xie on 16/8/28.
//  Copyright © 2016年 zhangchong. All rights reserved.
//

#import "ZCUserView.h"
#import "ZCEssenceModel.h"

#define defaultMargin 10

@interface ZCUserView ()

@property (weak, nonatomic) UIImageView *headerImage;
@property (weak, nonatomic) UIImageView *vipImage;
@property (weak, nonatomic) UILabel *nameLabel;
@property (weak, nonatomic) UILabel *creattimeLabel;

@property (weak, nonatomic) UIButton *addFriendBtn;


@end


@implementation ZCUserView

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
    }
    
    return self;
}
-(void)setupUI{
    
    UIImageView *headerImage = [[UIImageView alloc]init];
    self.headerImage = headerImage;
    headerImage.layer.cornerRadius = 15;
    headerImage.layer.masksToBounds = YES;
    
    UIImageView *vipImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Profile_AddV_authen"]];
    self.vipImage = vipImage;
    
    UILabel *nameLabel = [UILabel labelWithText:nil textColor:[UIColor grayColor] fontSize:12 textAlignment:NSTextAlignmentLeft];
    self.nameLabel = nameLabel;
    
    UILabel *creattimeLabel = [UILabel labelWithText:nil textColor:[UIColor grayColor] fontSize:10 textAlignment:NSTextAlignmentLeft];
    self.creattimeLabel = creattimeLabel;

    
    UIButton *addFriendBtn = [UIButton buttonWithBackgroundImage:@"cellFollowIcon" highlightedImage:@"cellFollowClickIcon" disabledImage:@"cellFollowDisableIcon"];
    [addFriendBtn addTarget:self action:@selector(addFriendButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.addFriendBtn = addFriendBtn;
    
    
    [self addSubview:headerImage];
    [self addSubview:vipImage];
    [self addSubview:nameLabel];
    [self addSubview:creattimeLabel];
    [self addSubview:addFriendBtn];
    
    [headerImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.equalTo(self).offset(defaultMargin);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(30);
    }];
    
    [vipImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(headerImage);
        make.bottom.equalTo(headerImage);
        make.width.height.mas_equalTo(10);
    }];
    
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headerImage);
        make.leading.equalTo(headerImage.mas_trailing).offset(defaultMargin);
    }];
    
    [creattimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(nameLabel);
        make.bottom.equalTo(headerImage);
    }];
    
    [addFriendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headerImage);
        make.trailing.equalTo(self).offset(-10);
    }];
    
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(headerImage.mas_bottom).offset(10);
    }];
}

-(void)setModel:(ZCEssenceModel *)model{
    _model = model;
    
    [self.headerImage sd_setImageWithURL:[NSURL URLWithString:model.profile_image] placeholderImage:[UIImage imageNamed:@"defaultUserIcon"]];
    self.nameLabel.text = model.name;
    self.creattimeLabel.text = model.passtime;
    
}

-(void)addFriendButtonAction:(UIButton*)sender{
    
    sender.enabled = !sender.enabled;
}


@end
